<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../css/base.css"/>
    <link rel="stylesheet" type="text/css" href="../css/common.css"/>
    <link rel="stylesheet" type="text/css" href="../css/message.css"/>
    
</head>
<body>
<script id="act-template" type="text/x-dot-template">
{{ for(var i=0; i< it.length; i++) { }}
	<article onclick="openGoodsDetail({{=it[i].shopid}})">
			<div class='time'>
				<span>{{=it[i].m_time}}</span>
			</div>
			<dl class="border-img">
				<div>
					<dt>{{=it[i].title}}</dt>
					<dd class="border-bottom-img">{{=it[i].content}}</dd>
				</div>
				
				<div class='detail'>
					<span>查看详情</span>
					<i></i>
				</div>
			</dl>
		</article>
		
{{}}}
</script>
	<div id='jqm-lotteryMessage'>
		
		
		
	</div>
	<!-- <div id='more' style="text-align: center;height: 30px;line-height: 30px; color: #666">正在加载...</div> -->
</body>
<script type="text/javascript" src="../script/api.js"></script>
	<script type="text/javascript" src="../script/doT.min.js"></script>
	<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript">
	var uid = null;
	apiready = function(){
		uid = $api.getStorage('user').uid;
		api.ajax({
	        url:'http://wap.jqmao.cn/updateLottMessage?uid='+uid
        },function(ret,err){
        	//coding...
        	if(ret){
				if(ret.code=='0'){
					api.sendEvent({
					    name: 'myread',
					    extra: {
					        read: 'Y'
					    }
					});
				}
        	}else{
        		//alert(JSON.stringify(err));
        	}
        });
        
		

	getBuyRecord(uid,true);
	function getBuyRecord(uid,isReload,currentPage) {
    var pageSize = 10;
    currentPage=isReload?0:currentPage;
    	api.ajax({
        url: 'http://wap.jqmao.cn/getLottMessageList',
        method: 'post',
        data: {
            values: {uid: uid, pageSize: pageSize,currentPage:currentPage,type:'2'}
        }
    }, function (ret, err) {

        if (ret) {
        	//alert(JSON.stringify(ret));
            total = ret['total']
            var content = $api.byId('jqm-lotteryMessage');
            var tpl = $api.byId('act-template').text;
            var tempFn = doT.template(tpl);
            //alert($api.getStorage('type'));
            //alert(type)
            api.hideProgress();

            if (isReload) {
                $api.setStorage("currentPage", 0);        // 重新设置为0
                $api.html(content, tempFn(ret['listItems']));
                
            } else {
                $api.append(content, tempFn(ret['listItems']));
            }


        } else {
           //alert(JSON.stringify(err));
        }
        
    });
    }
    //上拉加载
    api.addEventListener({

        name: 'scrolltobottom',
        extra: {
            threshold: 0 //设置距离底部多少距离时触发，默认值为0，数字类型
        }
    }, function (ret, err) {
       
        $api.css($api.byId('more'),'display:block');
        var _page=parseInt($api.getStorage("currentPage"));
        if(_page+10<=total){

         getBuyRecord(uid,false,_page+10);
        $api.setStorage("currentPage", _page+10); // 页码+1
        }else{
           $api.css($api.byId('more'),'display:none');
        }
      
       
    });
    	};
	
</script>
</html>